<template>
  <div class="profile-page">
    <!-- 个人资料卡片 -->
    <div class="profile-card">
      <!-- 背景装饰 -->
      <div class="profile-background">
      </div>
      
      <!-- 头像区域 -->
      <div class="avatar-section">
        <div class="user-avatar">
          <img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Ccircle cx='50' cy='50' r='50' fill='%2332CD32'/%3E%3Ctext x='50' y='65' font-size='40' text-anchor='middle' fill='white'%3E👨‍💻%3C/text%3E%3C/svg%3E" alt="头像" />
        </div>
      </div>
      
      <!-- 用户信息 -->
      <div class="user-info">
        <h2 class="username">{{ userProfile.name }}</h2>
        <p class="user-handle">@{{ userProfile.handle }}</p>
      </div>
      
      <!-- 统计信息 -->
      <div class="stats-section">
          <div class="stat-item">
            <div class="stat-number">{{ userProfile.connections }}</div>
            <div class="stat-label">连接</div>
          </div>
        </div>
    </div>

    <!-- 技能和设备展示 -->
    <div class="content-section">
      <!-- 我的技能 -->
      <div class="info-section">
        <div class="section-header">
          <h3 class="section-title">我的技能</h3>
          <button class="add-skill-btn" @click="goToAddSkill">
            <span class="plus-icon">+</span>
          </button>
        </div>
        <div class="tags-container">
          <span 
            v-for="(skill, index) in getAllSkills()"
            :key="index"
            class="skill-tag"
          >
            {{ skill }}
          </span>
        </div>
      </div>

      <!-- 可共享设备 -->
      <div class="info-section">
        <div class="section-header">
          <h3 class="section-title">可共享设备</h3>
          <button class="add-device-btn" @click="goToAddDevice">
            <span class="plus-icon">+</span>
          </button>
        </div>
        <div class="tags-container">
          <span 
            v-for="(device, index) in getAllDevices()"
            :key="index"
            class="device-tag"
          >
            {{ device }}
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Profile',
  data() {
    return {
      userProfile: {
        name: '张小明',
        handle: '@zhangxiaoming',
        connections: 12,
        skills: ['编程', '数据', '摄影'],
        devices: ['电钻', '卡槽']
      },
      userSkills: [],
      userDevices: []
    }
  },
  mounted() {
    this.loadUserSkills()
    this.loadUserDevices()
  },
  methods: {
    goToAddSkill() {
      this.$router.push('/add-skill')
    },
    goToAddDevice() {
      this.$router.push('/add-device')
    },
    loadUserSkills() {
      // 从localStorage加载用户技能
      const savedSkills = JSON.parse(localStorage.getItem('userSkills') || '[]')
      this.userSkills = savedSkills
    },
    loadUserDevices() {
      // 从localStorage加载用户设备
      const savedDevices = JSON.parse(localStorage.getItem('userDevices') || '[]')
      this.userDevices = savedDevices
    },
    getAllSkills() {
      // 合并默认技能和用户添加的技能
      const defaultSkills = this.userProfile.skills
      const userSkillNames = this.userSkills.map(skill => skill.name)
      return [...defaultSkills, ...userSkillNames]
    },
    getAllDevices() {
      // 合并默认设备和用户添加的设备
      const defaultDevices = this.userProfile.devices
      const userDeviceNames = this.userDevices.map(device => device.name)
      return [...defaultDevices, ...userDeviceNames]
    }
  }
}
</script>

<style scoped>
.profile-page {
  min-height: 100vh;
  background: #f5f5f5;
  padding: 20px;
  padding-bottom: 100px;
}

.profile-card {
  background: linear-gradient(135deg, #64b5f6, #90caf9);
  border-radius: 20px;
  padding: 40px 20px 30px;
  margin-bottom: 20px;
  position: relative;
  color: white;
  text-align: center;
}

.profile-background {
  position: absolute;
  top: 20px;
  right: 20px;
}

.avatar-section {
  margin-bottom: 20px;
}

.user-avatar {
  width: 80px;
  height: 80px;
  margin: 0 auto;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 3px solid white;
}

.user-info {
  margin-bottom: 25px;
}

.username {
  font-size: 24px;
  font-weight: bold;
  margin: 0 0 5px 0;
  color: white;
}

.user-handle {
  font-size: 16px;
  margin: 0;
  opacity: 0.8;
  color: white;
}

.stats-section {
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.stat-item {
  text-align: center;
}

.stat-number {
  font-size: 24px;
  font-weight: bold;
  color: white;
  margin-bottom: 5px;
}

.stat-label {
  font-size: 14px;
  opacity: 0.8;
  color: white;
  margin: 0;
}

.content-section {
  background: white;
  border-radius: 15px;
  padding: 20px;
  margin-bottom: 20px;
}

.info-section {
  margin-bottom: 28px;
}

.info-section {
  margin-bottom: 28px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  color: #2c3e50;
  margin: 0;
  position: relative;
  padding-left: 12px;
}

.section-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 20px;
  background: linear-gradient(135deg, #64b5f6, #42a5f5);
  border-radius: 2px;
}

.add-skill-btn,
.add-device-btn {
  background: linear-gradient(135deg, #42a5f5, #90caf9);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(66, 165, 245, 0.3);
}

.add-skill-btn:hover,
.add-device-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(66, 165, 245, 0.4);
}

.plus-icon {
  color: white;
  font-size: 18px;
  font-weight: bold;
  line-height: 1;
}

.tags-container {
  display: flex;
  flex-wrap: wrap;
  margin-top: 8px;
}

.skill-tag {
  background: linear-gradient(135deg, #42a5f5, #90caf9);
  color: white;
  padding: 10px 18px;
  border-radius: 25px;
  font-size: 14px;
  font-weight: 500;
  margin: 6px 8px 6px 0;
  display: inline-block;
  box-shadow: 0 2px 8px rgba(66, 165, 245, 0.3);
  transition: all 0.3s ease;
}

.skill-tag:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(66, 165, 245, 0.4);
}

.device-tag {
  background: linear-gradient(135deg, #26a69a, #80cbc4);
  color: white;
  padding: 10px 18px;
  border-radius: 25px;
  font-size: 14px;
  font-weight: 500;
  margin: 6px 8px 6px 0;
  display: inline-block;
  box-shadow: 0 2px 8px rgba(38, 166, 154, 0.3);
  transition: all 0.3s ease;
}

.device-tag:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(38, 166, 154, 0.4);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .profile-page {
    padding: 10px;
  }
  
  .profile-card {
    padding: 30px 15px 25px;
  }
  
  .stats-section {
    gap: 20px;
  }
  
  .content-section {
    padding: 15px;
  }
}
</style>